<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 6.3.0">
<link rel="preconnect" href="https://fonts.googleapis.com" crossorigin>
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300italic,400,400italic,700,700italic%7CZCOOL+QingKe+HuangYou:300,300italic,400,400italic,700,700italic%7CNoto+Sans+Simplified+Chinese:300,300italic,400,400italic,700,700italic%7CJetBrains+Mono:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">

<link rel="stylesheet" href="/lib/@fortawesome/fontawesome-free/css/all.min.css" integrity="sha256-HtsXJanqjKTc8vVQjO4YMhiqFoXkfBsjBWcX91T1jr8=" crossorigin="anonymous">
  <link rel="stylesheet" href="/lib/animate.css/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="/lib/@fancyapps/ui/dist/fancybox/fancybox.css" integrity="sha256-RvRHGSuWAxZpXKV9lLDt2e+rZ+btzn48Wp4ueS3NZKs=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"wyatex.online","root":"/","images":"/images","scheme":"Pisces","darkmode":true,"version":"8.18.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":false,"height":500},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":true}}</script><script src="/js/config.js"></script>

    <meta name="description" content="在学习 TS 黑魔法（类型体操），建议先把前面的 TS 基础知识学好了，再来看进阶用法。 另外，即使已经进阶到高级选手了：不要滥用工具类型，对外暴露的 API，应该尽量多手动标注函数返回值类型。契约高于实现，你写再多重复的TS代码也不会影响最终代码。">
<meta property="og:type" content="article">
<meta property="og:title" content="TypeScript黑魔法教学（2）：开始练习体操">
<meta property="og:url" content="https://wyatex.online/TypeScript/ts%E9%BB%91%E9%AD%94%E6%B3%95%E6%95%99%E5%AD%A6%EF%BC%882%EF%BC%89%EF%BC%9A%E5%BC%80%E5%A7%8B%E7%BB%83%E4%B9%A0%E4%BD%93%E6%93%8D/index.html">
<meta property="og:site_name" content="Wyatex&#96;s blog">
<meta property="og:description" content="在学习 TS 黑魔法（类型体操），建议先把前面的 TS 基础知识学好了，再来看进阶用法。 另外，即使已经进阶到高级选手了：不要滥用工具类型，对外暴露的 API，应该尽量多手动标注函数返回值类型。契约高于实现，你写再多重复的TS代码也不会影响最终代码。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-06-28T01:30:02.000Z">
<meta property="article:modified_time" content="2023-07-26T01:21:02.230Z">
<meta property="article:author" content="Wyatex">
<meta property="article:tag" content="前端">
<meta property="article:tag" content="学习笔记">
<meta property="article:tag" content="TypeScript">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://wyatex.online/TypeScript/ts%E9%BB%91%E9%AD%94%E6%B3%95%E6%95%99%E5%AD%A6%EF%BC%882%EF%BC%89%EF%BC%9A%E5%BC%80%E5%A7%8B%E7%BB%83%E4%B9%A0%E4%BD%93%E6%93%8D/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://wyatex.online/TypeScript/ts%E9%BB%91%E9%AD%94%E6%B3%95%E6%95%99%E5%AD%A6%EF%BC%882%EF%BC%89%EF%BC%9A%E5%BC%80%E5%A7%8B%E7%BB%83%E4%B9%A0%E4%BD%93%E6%93%8D/","path":"TypeScript/ts黑魔法教学（2）：开始练习体操/","title":"TypeScript黑魔法教学（2）：开始练习体操"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>TypeScript黑魔法教学（2）：开始练习体操 | Wyatex`s blog</title>
  








  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">Wyatex`s blog</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">97</span></a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">26</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">155</span></a></li><li class="menu-item menu-item-编程"><a href="/programming/" rel="section"><i class="fa fa-book fa-fw"></i>编程</a></li><li class="menu-item menu-item-蹲坑读物"><a href="/%E5%B9%B2%E8%B4%A7/%E5%BC%80%E5%8F%91%E4%BA%A4%E6%B5%81%E7%BE%A4%E5%88%86%E4%BA%AB%E8%AE%B0%E5%BD%95/" rel="section"><i class="fa fa-book fa-fw"></i>蹲坑读物</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E3%80%81%E6%95%B0%E7%BB%84%E6%8B%86%E8%A7%A3"><span class="nav-number">1.</span> <span class="nav-text">字符串、数组拆解</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%81%8D%E5%8E%86"><span class="nav-number">2.</span> <span class="nav-text">遍历</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%81%94%E5%90%88%E7%B1%BB%E5%9E%8B"><span class="nav-number">2.1.</span> <span class="nav-text">联合类型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%98%A0%E5%B0%84%E7%B1%BB%E5%9E%8B"><span class="nav-number">2.2.</span> <span class="nav-text">映射类型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%85%83%E7%BB%84"><span class="nav-number">2.3.</span> <span class="nav-text">元组</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="nav-number">2.4.</span> <span class="nav-text">字符串</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%81%94%E5%90%88%E7%B1%BB%E5%9E%8B%E5%8F%98%E4%BA%A4%E5%8F%89%E7%B1%BB%E5%9E%8B"><span class="nav-number">3.</span> <span class="nav-text">联合类型变交叉类型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%A4%E6%96%AD%E4%B8%A4%E4%B8%AA%E7%B1%BB%E5%9E%8B%E7%9B%B8%E7%AD%89"><span class="nav-number">4.</span> <span class="nav-text">判断两个类型相等</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%AE%A1%E6%95%B0"><span class="nav-number">5.</span> <span class="nav-text">计数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8A%A0%E5%87%8F%E8%BF%90%E7%AE%97"><span class="nav-number">6.</span> <span class="nav-text">加减运算</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Wyatex"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Wyatex</p>
  <div class="site-description" itemprop="description">这里是我用来做笔记的网站哟~</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">155</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">26</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">97</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/wyatex" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;wyatex" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:wyatex@qq.com" title="E-Mail → mailto:wyatex@qq.com" rel="noopener me" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
    <div class="sidebar-inner sidebar-blogroll">
      <div class="links-of-blogroll animated">
        <div class="links-of-blogroll-title"><i class="fa fa-globe fa-fw"></i>
          链接
        </div>
        <ul class="links-of-blogroll-list">
            <li class="links-of-blogroll-item">
              <a href="https://antfu.me/" title="https:&#x2F;&#x2F;antfu.me&#x2F;" rel="noopener" target="_blank">Anthony Fu</a>
            </li>
            <li class="links-of-blogroll-item">
              <a href="https://www.codesky.me/" title="https:&#x2F;&#x2F;www.codesky.me&#x2F;" rel="noopener" target="_blank">CodeSky</a>
            </li>
            <li class="links-of-blogroll-item">
              <a href="https://learn.lianglianglee.com/" title="https:&#x2F;&#x2F;learn.lianglianglee.com&#x2F;" rel="noopener" target="_blank">技术文章摘抄</a>
            </li>
        </ul>
      </div>
    </div>
        <div class="pjax">
        <div class="sidebar-inner sidebar-post-related">
          <div class="animated">
              <div class="links-of-blogroll-title"><i class="fa fa-signs-post fa-fw"></i>
    相关文章
  </div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      <a class="popular-posts-link" href="/TypeScript/ts%E9%BB%91%E9%AD%94%E6%B3%95%E6%95%99%E5%AD%A6%EF%BC%881%EF%BC%89%EF%BC%9A%E5%89%8D%E7%BD%AE%E7%9F%A5%E8%AF%86/" rel="bookmark">
        <time class="popular-posts-time">2023-04-20</time>
        <br>
      TypeScript黑魔法教学（1）：前置知识
      </a>
    </li>
    <li class="popular-posts-item">
      <a class="popular-posts-link" href="/TypeScript/ts%E7%AC%94%E8%AE%B0%EF%BC%885%EF%BC%89%EF%BC%9A%E5%AE%98%E6%96%B9%E5%B7%A5%E5%85%B7%E7%B1%BB%E3%80%81%E6%89%93%E9%80%A0%E8%87%AA%E5%B7%B1%E7%9A%84%E5%B7%A5%E5%85%B7%E7%B1%BB%E5%9E%8B/" rel="bookmark">
        <time class="popular-posts-time">2021-11-13</time>
        <br>
      ts笔记（5）：官方工具类、打造自己的工具类型
      </a>
    </li>
    <li class="popular-posts-item">
      <a class="popular-posts-link" href="/TypeScript/ts%E7%AC%94%E8%AE%B0%EF%BC%886%EF%BC%89%EF%BC%9A%E4%BD%BF%E7%94%A8TypeScript%E5%BC%80%E5%8F%91Node.js%E5%BA%94%E7%94%A8/" rel="bookmark">
        <time class="popular-posts-time">2021-11-15</time>
        <br>
      ts笔记（6）：常见TypeScript错误、开发Node.js应用
      </a>
    </li>
  </ul>

          </div>
        </div>
        </div>
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wyatex.online/TypeScript/ts%E9%BB%91%E9%AD%94%E6%B3%95%E6%95%99%E5%AD%A6%EF%BC%882%EF%BC%89%EF%BC%9A%E5%BC%80%E5%A7%8B%E7%BB%83%E4%B9%A0%E4%BD%93%E6%93%8D/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Wyatex">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Wyatex`s blog">
      <meta itemprop="description" content="这里是我用来做笔记的网站哟~">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="TypeScript黑魔法教学（2）：开始练习体操 | Wyatex`s blog">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          TypeScript黑魔法教学（2）：开始练习体操
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-06-28 09:30:02" itemprop="dateCreated datePublished" datetime="2023-06-28T09:30:02+08:00">2023-06-28</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-07-26 09:21:02" itemprop="dateModified" datetime="2023-07-26T09:21:02+08:00">2023-07-26</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/TypeScript/" itemprop="url" rel="index"><span itemprop="name">TypeScript</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>在学习 TS 黑魔法（类型体操），建议先把<a href="/categories/TypeScript/">前面的 TS 基础知识</a>学好了，再来看进阶用法。</p>
<p>另外，即使已经进阶到高级选手了：<strong>不要滥用工具类型，对外暴露的 API，应该尽量多手动标注函数返回值类型。契约高于实现，你写再多重复的TS代码也不会影响最终代码。</strong></p>
<span id="more"></span>

<h2 id="字符串、数组拆解"><a href="#字符串、数组拆解" class="headerlink" title="字符串、数组拆解"></a>字符串、数组拆解</h2><p>数组可以直接用类似js的 <code>[infer start, ...infer M, infer end]</code> 来获得一个数组的第一个和最后一个值。<br>字符串也是 <code>$&#123;infer L&#125;$&#123;infer M&#125;$&#123;infer R&#125;</code> ，但注意这里L是第一个字符，M是第二个字符，R是剩下的字符，如果字符只有2个，则R是’’，如果字符只有一位，则无法这么拆解成3个变量，<code>T extends infer $&#123;infer L&#125;$&#123;infer M&#125;$&#123;infer R&#125;</code>条件会走到false的语句里去，这一点比较奇怪。</p>
<figure class="highlight ts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 15 实现一个通用Last&lt;T&gt;，它接受一个数组T并返回其最后一个元素的类型。</span></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">Last</span>&lt;T <span class="keyword">extends</span> <span class="built_in">any</span>[]&gt; = T <span class="keyword">extends</span> [...infer B, infer P] ? P : <span class="built_in">never</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> arr1 = [<span class="string">&#x27;a&#x27;</span>, <span class="string">&#x27;b&#x27;</span>, <span class="string">&#x27;c&#x27;</span>]</span><br><span class="line"><span class="keyword">type</span> arr2 = [<span class="number">3</span>, <span class="number">2</span>, <span class="number">1</span>]</span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> tail1 = <span class="title class_">Last</span>&lt;arr1&gt; <span class="comment">// expected to be &#x27;c&#x27;</span></span><br><span class="line"><span class="keyword">type</span> tail2 = <span class="title class_">Last</span>&lt;arr2&gt; <span class="comment">// expected to be 1</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">// 实现 Replace&lt;S, From, To&gt; 将字符串 S 中的第一个子字符串 From 替换为 To 。</span></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">Replace</span>&lt;S <span class="keyword">extends</span> <span class="built_in">string</span>, <span class="title class_">From</span> <span class="keyword">extends</span> <span class="built_in">string</span>, <span class="title class_">To</span> <span class="keyword">extends</span> <span class="built_in">string</span>&gt; = <span class="title class_">From</span> <span class="keyword">extends</span> <span class="string">&#x27;&#x27;</span> </span><br><span class="line">? S </span><br><span class="line">: S <span class="keyword">extends</span> (<span class="string">`<span class="subst">$&#123;infer L&#125;</span><span class="subst">$&#123;From&#125;</span><span class="subst">$&#123;infer R&#125;</span>`</span>) ? <span class="string">`<span class="subst">$&#123;L&#125;</span><span class="subst">$&#123;To&#125;</span><span class="subst">$&#123;R&#125;</span>`</span>: S</span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> replaced = <span class="title class_">Replace</span>&lt;<span class="string">&#x27;types are fun!&#x27;</span>, <span class="string">&#x27;fun&#x27;</span>, <span class="string">&#x27;awesome&#x27;</span>&gt; <span class="comment">// 期望是 &#x27;types are awesome!&#x27;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="遍历"><a href="#遍历" class="headerlink" title="遍历"></a>遍历</h2><h3 id="联合类型"><a href="#联合类型" class="headerlink" title="联合类型"></a>联合类型</h3><p>类似结构的联合类型可以直接通过extends条件语句遍历到</p>
<figure class="highlight ts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">interface</span> <span class="title class_">Cat</span> &#123;</span><br><span class="line">  <span class="attr">type</span>: <span class="string">&#x27;cat&#x27;</span></span><br><span class="line">  <span class="attr">breeds</span>: <span class="string">&#x27;Abyssinian&#x27;</span> | <span class="string">&#x27;Shorthair&#x27;</span> | <span class="string">&#x27;Curl&#x27;</span> | <span class="string">&#x27;Bengal&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">interface</span> <span class="title class_">Dog</span> &#123;</span><br><span class="line">  <span class="attr">type</span>: <span class="string">&#x27;dog&#x27;</span></span><br><span class="line">  <span class="attr">breeds</span>: <span class="string">&#x27;Hound&#x27;</span> | <span class="string">&#x27;Brittany&#x27;</span> | <span class="string">&#x27;Bulldog&#x27;</span> | <span class="string">&#x27;Boxer&#x27;</span></span><br><span class="line">  <span class="attr">color</span>: <span class="string">&#x27;brown&#x27;</span> | <span class="string">&#x27;white&#x27;</span> | <span class="string">&#x27;black&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">LookUp</span>&lt;T, K <span class="keyword">extends</span> <span class="built_in">string</span>&gt; = T <span class="keyword">extends</span> &#123; <span class="attr">type</span>: K &#125; ? T : <span class="built_in">never</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">MyDog</span> = <span class="title class_">LookUp</span>&lt;<span class="title class_">Cat</span> | <span class="title class_">Dog</span>, <span class="string">&#x27;dog&#x27;</span>&gt; <span class="comment">// expected to be `Dog`</span></span><br></pre></td></tr></table></figure>

<p>这个特性可以做些变态的事了，譬如把联合类型组成笛卡尔积的数组，直接看: <a target="_blank" rel="noopener" href="https://github.com/type-challenges/type-challenges/issues/614">Permutation (with explanations)</a></p>
<figure class="highlight ts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">Permutation</span>&lt;T, K=T&gt; =</span><br><span class="line">    [T] <span class="keyword">extends</span> [<span class="built_in">never</span>]</span><br><span class="line">      ? []</span><br><span class="line">      : K <span class="keyword">extends</span> K</span><br><span class="line">        ? [K, ...<span class="title class_">Permutation</span>&lt;<span class="title class_">Exclude</span>&lt;T, K&gt;&gt;]</span><br><span class="line">        : <span class="built_in">never</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> perm = <span class="title class_">Permutation</span>&lt;<span class="string">&#x27;A&#x27;</span> | <span class="string">&#x27;B&#x27;</span> | <span class="string">&#x27;C&#x27;</span>&gt;; </span><br><span class="line"><span class="comment">// [&#x27;A&#x27;, &#x27;B&#x27;, &#x27;C&#x27;] | [&#x27;A&#x27;, &#x27;C&#x27;, &#x27;B&#x27;] | [&#x27;B&#x27;, &#x27;A&#x27;, &#x27;C&#x27;] | [&#x27;B&#x27;, &#x27;C&#x27;, &#x27;A&#x27;] | [&#x27;C&#x27;, &#x27;A&#x27;, &#x27;B&#x27;] | [&#x27;C&#x27;, &#x27;B&#x27;, &#x27;A&#x27;]</span></span><br></pre></td></tr></table></figure>

<h3 id="映射类型"><a href="#映射类型" class="headerlink" title="映射类型"></a>映射类型</h3><p>通过 <code>extends keyof T</code> 进行遍历</p>
<figure class="highlight ts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">ObjectEntries</span>&lt;T <span class="keyword">extends</span> <span class="title class_">Record</span>&lt;<span class="built_in">string</span>, <span class="built_in">any</span>&gt;, K = keyof T&gt; = K <span class="keyword">extends</span> keyof T ? [K, T[K]]: [];</span><br><span class="line"></span><br><span class="line"><span class="keyword">interface</span> <span class="title class_">Model</span> &#123;</span><br><span class="line">  <span class="attr">name</span>: <span class="built_in">string</span>;</span><br><span class="line">  <span class="attr">age</span>: <span class="built_in">number</span>;</span><br><span class="line">  <span class="attr">locations</span>: <span class="built_in">string</span>[] | <span class="literal">null</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">type</span> modelEntries = <span class="title class_">ObjectEntries</span>&lt;<span class="title class_">Model</span>&gt; <span class="comment">// [&#x27;name&#x27;, string] | [&#x27;age&#x27;, number] | [&#x27;locations&#x27;, string[] | null];</span></span><br></pre></td></tr></table></figure>

<h3 id="元组"><a href="#元组" class="headerlink" title="元组"></a>元组</h3><p>元组的遍历，借助元组解构逐个处理逻辑，再把剩下的元组迭代调用当前的类型分析器</p>
<figure class="highlight ts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">PromiseParseAll</span>&lt;T <span class="keyword">extends</span> <span class="built_in">any</span>[]&gt; = T <span class="keyword">extends</span> [infer P, ...infer O]</span><br><span class="line">  ? P <span class="keyword">extends</span> <span class="title class_">Promise</span>&lt;infer R&gt; ? [R, ...<span class="title class_">PromiseParseAll</span>&lt;O&gt;] : [P, ...<span class="title class_">PromiseParseAll</span>&lt;O&gt;]</span><br><span class="line">  : []</span><br><span class="line"><span class="keyword">type</span> <span class="title class_">PromiseAll</span>&lt;T <span class="keyword">extends</span> <span class="built_in">any</span>[]&gt; = <span class="title class_">Promise</span>&lt;<span class="title class_">PromiseParseAll</span>&lt;T&gt;&gt;</span><br><span class="line"><span class="comment">// expected to be `Promise&lt;[number, 42, string]&gt;`</span></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">PRes</span> = <span class="title class_">PromiseAll</span>&lt;[<span class="title class_">Promise</span>&lt;<span class="built_in">number</span>&gt;, <span class="number">42</span>, <span class="title class_">Promise</span>&lt;<span class="built_in">string</span>&gt;]&gt;;</span><br></pre></td></tr></table></figure>

<h3 id="字符串"><a href="#字符串" class="headerlink" title="字符串"></a>字符串</h3><p>字符串类似</p>
<figure class="highlight ts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">TrimLeft</span>&lt;T <span class="keyword">extends</span> <span class="built_in">string</span>&gt; = T <span class="keyword">extends</span> <span class="string">`<span class="subst">$&#123;infer L&#125;</span><span class="subst">$&#123;infer R&#125;</span>`</span></span><br><span class="line">? L <span class="keyword">extends</span> <span class="string">&quot; &quot;</span>|<span class="string">&quot;\n&quot;</span>|<span class="string">&quot;\t&quot;</span> ? <span class="title class_">TrimLeft</span>&lt;R&gt; : T</span><br><span class="line">: <span class="built_in">never</span></span><br><span class="line"><span class="keyword">type</span> trimed = <span class="title class_">TrimLeft</span>&lt;<span class="string">&#x27;  Hello World &#x27;</span>&gt; <span class="comment">// 应推导出 &#x27;Hello World &#x27;</span></span><br></pre></td></tr></table></figure>

<h2 id="联合类型变交叉类型"><a href="#联合类型变交叉类型" class="headerlink" title="联合类型变交叉类型"></a>联合类型变交叉类型</h2><p>利用函数入参的逆变特性，把输入类型构建成函数参数</p>
<figure class="highlight ts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">UnionToIntersection</span>&lt;U&gt; = </span><br><span class="line">  (U <span class="keyword">extends</span> <span class="built_in">any</span> </span><br><span class="line">   ? <span class="function">(<span class="params">arg: U</span>) =&gt;</span> <span class="built_in">any</span> </span><br><span class="line">   : <span class="built_in">never</span></span><br><span class="line">  ) <span class="keyword">extends</span> (<span class="function">(<span class="params">arg: infer I</span>) =&gt;</span> <span class="built_in">any</span>) </span><br><span class="line">  ? I </span><br><span class="line">  : <span class="built_in">never</span></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">TestUnion2Intersection</span> = <span class="title class_">UnionToIntersection</span>&lt;&#123;<span class="attr">a</span>: <span class="number">1</span>&#125; | &#123;<span class="attr">b</span>: <span class="number">2</span>&#125; | &#123;<span class="attr">c</span>: <span class="number">3</span>&#125;&gt; </span><br><span class="line"><span class="comment">// expected to be &#123;a: 1&#125; &amp; &#123;b: 2&#125; &amp; &#123;c: 3&#125;</span></span><br></pre></td></tr></table></figure>


<h2 id="判断两个类型相等"><a href="#判断两个类型相等" class="headerlink" title="判断两个类型相等"></a>判断两个类型相等</h2><p>大多数非严格情况下的相等使用 <code>A extends B</code> 基本可以做到，譬如前一步的类型中间方法根据条件返回了true或false，接下来要判断结果是否是true，直接用 <code>T extends true ? xxx : xxx</code> 进行接下来的操作就好。</p>
<p>但是枚举类型下，extends无法很好的区分是否可选，是否只读的区别。</p>
<figure class="highlight ts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> a = &#123;<span class="attr">a</span>: <span class="built_in">string</span>&#125; <span class="keyword">extends</span> &#123;<span class="keyword">readonly</span> <span class="attr">a</span>: <span class="built_in">string</span>&#125; ? <span class="literal">true</span> : <span class="literal">false</span>; <span class="comment">// true</span></span><br><span class="line"><span class="keyword">type</span> b = &#123;<span class="keyword">readonly</span> <span class="attr">a</span>: <span class="built_in">string</span>&#125; <span class="keyword">extends</span> &#123;<span class="attr">a</span>: <span class="built_in">string</span>&#125; ? <span class="literal">true</span> : <span class="literal">false</span>; <span class="comment">// true</span></span><br><span class="line"><span class="keyword">type</span> c = &#123;<span class="attr">a</span>: <span class="built_in">string</span>&#125; <span class="keyword">extends</span> &#123;a?: <span class="built_in">string</span>&#125; ? <span class="literal">true</span> : <span class="literal">false</span>; <span class="comment">// true</span></span><br><span class="line"><span class="keyword">type</span> d = &#123;a?: <span class="built_in">string</span>&#125; <span class="keyword">extends</span> &#123;<span class="attr">a</span>: <span class="built_in">string</span>&#125; ? <span class="literal">true</span> : <span class="literal">false</span>; <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<p>所以严格的相等要借助函数的协变，具体的逻辑我也没get到。。。</p>
<figure class="highlight ts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">type</span> <span class="title class_">Equal</span>&lt;X, Y&gt; =</span><br><span class="line">  (&lt;T&gt;<span class="function">() =&gt;</span> T <span class="keyword">extends</span> X ? <span class="number">1</span> : <span class="number">2</span>) <span class="keyword">extends</span></span><br><span class="line">  (&lt;T&gt;<span class="function">() =&gt;</span> T <span class="keyword">extends</span> Y ? <span class="number">1</span> : <span class="number">2</span>) ? <span class="literal">true</span> : <span class="literal">false</span></span><br></pre></td></tr></table></figure>

<h2 id="计数"><a href="#计数" class="headerlink" title="计数"></a>计数</h2><p>ts类型是无法进行数学加减运算的，有运算或者计数的诉求，都可以构建一个元组，用元组的length来计数</p>
<figure class="highlight ts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">FlattenDepth</span>&lt;</span><br><span class="line">  T <span class="keyword">extends</span> <span class="built_in">unknown</span>[],</span><br><span class="line">  <span class="title class_">Depth</span> <span class="keyword">extends</span> <span class="built_in">number</span> = <span class="number">1</span>,</span><br><span class="line">  <span class="title class_">Count</span> <span class="keyword">extends</span> <span class="number">1</span>[] = []</span><br><span class="line">&gt; =</span><br><span class="line">  <span class="title class_">Count</span>[<span class="string">&#x27;length&#x27;</span>] <span class="keyword">extends</span> <span class="title class_">Depth</span></span><br><span class="line">  ? T</span><br><span class="line">  : T <span class="keyword">extends</span> [infer <span class="title class_">Head</span>, ...infer <span class="title class_">Tail</span>]</span><br><span class="line">    ? <span class="title class_">Head</span> <span class="keyword">extends</span> <span class="built_in">unknown</span>[]</span><br><span class="line">      ? [</span><br><span class="line">          ...<span class="title class_">FlattenDepth</span>&lt;<span class="title class_">Head</span>, <span class="title class_">Depth</span>, [...<span class="title class_">Count</span>, <span class="number">1</span>]&gt;,</span><br><span class="line">          ...<span class="title class_">FlattenDepth</span>&lt;<span class="title class_">Tail</span>, <span class="title class_">Depth</span>, <span class="title class_">Count</span>&gt;</span><br><span class="line">        ]</span><br><span class="line">      : [</span><br><span class="line">          <span class="title class_">Head</span>,</span><br><span class="line">          ...<span class="title class_">FlattenDepth</span>&lt;<span class="title class_">Tail</span>, <span class="title class_">Depth</span>, <span class="title class_">Count</span>&gt;</span><br><span class="line">        ]</span><br><span class="line">    : [];</span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> a = <span class="title class_">FlattenDepth</span>&lt;[<span class="number">1</span>, <span class="number">2</span>, [<span class="number">3</span>, <span class="number">4</span>], [[[<span class="number">5</span>]]]], <span class="number">2</span>&gt; <span class="comment">// [1, 2, 3, 4, [5]]. flattern 2 times</span></span><br><span class="line"><span class="keyword">type</span> b = <span class="title class_">FlattenDepth</span>&lt;[<span class="number">1</span>, <span class="number">2</span>, [<span class="number">3</span>, <span class="number">4</span>], [[[<span class="number">5</span>]]]]&gt; <span class="comment">// [1, 2, 3, 4, [[5]]]. Depth defaults to be 1</span></span><br></pre></td></tr></table></figure>

<h2 id="加减运算"><a href="#加减运算" class="headerlink" title="加减运算"></a>加减运算</h2><figure class="highlight ts"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> <span class="title class_">Fibonacci</span>&lt;</span><br><span class="line">  T <span class="keyword">extends</span> <span class="built_in">number</span>,</span><br><span class="line">  <span class="title class_">CurrentIndex</span> <span class="keyword">extends</span> <span class="built_in">any</span>[] = [<span class="string">&#x27;&#x27;</span>],</span><br><span class="line">  <span class="title class_">Prev</span> <span class="keyword">extends</span> <span class="built_in">any</span>[] = [],</span><br><span class="line">  <span class="title class_">Current</span> <span class="keyword">extends</span> <span class="built_in">any</span>[] = [<span class="string">&#x27;&#x27;</span>]</span><br><span class="line">&gt; =</span><br><span class="line">  <span class="title class_">CurrentIndex</span>[<span class="string">&#x27;length&#x27;</span>] <span class="keyword">extends</span> T</span><br><span class="line">  ? <span class="title class_">Current</span>[<span class="string">&#x27;length&#x27;</span>]</span><br><span class="line">  : <span class="title class_">Fibonacci</span>&lt;</span><br><span class="line">      T,</span><br><span class="line">      [...<span class="title class_">CurrentIndex</span>, <span class="string">&#x27;&#x27;</span>],</span><br><span class="line">      <span class="title class_">Current</span>,</span><br><span class="line">      [...<span class="title class_">Prev</span>, ...<span class="title class_">Current</span>]</span><br><span class="line">    &gt;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">ResultFibonacci1</span> = <span class="title class_">Fibonacci</span>&lt;<span class="number">3</span>&gt; <span class="comment">// 2</span></span><br><span class="line"><span class="keyword">type</span> <span class="title class_">ResultFibonacci2</span> = <span class="title class_">Fibonacci</span>&lt;<span class="number">8</span>&gt; <span class="comment">// 21</span></span><br></pre></td></tr></table></figure>

    </div>

    
    
    

    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>Wyatex
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://wyatex.online/TypeScript/ts%E9%BB%91%E9%AD%94%E6%B3%95%E6%95%99%E5%AD%A6%EF%BC%882%EF%BC%89%EF%BC%9A%E5%BC%80%E5%A7%8B%E7%BB%83%E4%B9%A0%E4%BD%93%E6%93%8D/" title="TypeScript黑魔法教学（2）：开始练习体操">https://wyatex.online/TypeScript/ts黑魔法教学（2）：开始练习体操/</a>
  </li>
  <li class="post-copyright-license">
      <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="post-tags">
              <a href="/tags/%E5%89%8D%E7%AB%AF/" rel="tag"># 前端</a>
              <a href="/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" rel="tag"># 学习笔记</a>
              <a href="/tags/TypeScript/" rel="tag"># TypeScript</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/TypeORM/typeorm%E7%AC%94%E8%AE%B01/" rel="prev" title="typeorm笔记1">
                  <i class="fa fa-angle-left"></i> typeorm笔记1
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/TypeScript/%E4%B8%BA%E4%BB%80%E4%B9%88Object-keys%E4%B8%8D%E8%83%BD%E6%AD%A3%E7%A1%AE%E5%9C%B0%E7%B1%BB%E5%9E%8B%E6%8E%A8%E5%AF%BC/" rel="next" title="为什么Object.keys不能正确地类型推导">
                  为什么Object.keys不能正确地类型推导 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2019 – 
    <span itemprop="copyrightYear">2024</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Wyatex</span>
  </div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>

    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script size="300" alpha="0.6" zIndex="-1" src="/lib/ribbon.js/dist/ribbon.min.js"></script>
  <script src="/lib/animejs/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="/lib/@next-theme/pjax/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="/lib/@fancyapps/ui/dist/fancybox/fancybox.umd.js" integrity="sha256-q8XkJ6dj5VwSvzI8+nATCHHQG+Xv/dAZBCgqmu93zOY=" crossorigin="anonymous"></script>
  <script src="/lib/lozad/dist/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="/lib/hexo-generator-searchdb/dist/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>



  
  <script data-pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





</body>
</html>
